package com.adv.ems.model.vo;

import com.adv.ems.db.entity.BuildingInfoDO;
import com.adv.ems.db.entity.DepartmentInfoDO;
import com.adv.ems.db.entity.MeterDO;
import com.adv.ems.enums.SubjectTypeEnum;
import com.adv.ems.utils.EmsUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
public class BaseDiagramRelateListVO {
    private List<Info> meters;
    private List<Info> subjects;

    public BaseDiagramRelateListVO() {
        this.meters = new ArrayList<Info>();
        this.subjects = new ArrayList<Info>();
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Info {
        private Long relationId;
        private Long subjectId;
        private String subjectName;
        private SubjectTypeEnum subjectType;

        public Info(Long relationId, MeterDO m) {
            this.relationId = relationId;
            this.subjectId = m.getId();
            this.subjectName = m.getName();
            this.subjectType = SubjectTypeEnum.METER;
        }

        public Info(Long relationId, BuildingInfoDO m, String acceptLanguage) {
            this.relationId = relationId;
            this.subjectId = m.getId();
            this.subjectName = EmsUtil.getNameInfo(m.getNameInfo(), acceptLanguage).getShortName();
            this.subjectType = SubjectTypeEnum.BUILDING;
        }

        public Info(Long relationId, DepartmentInfoDO m, String acceptLanguage) {
            this.relationId = relationId;
            this.subjectId = m.getId();
            this.subjectName = EmsUtil.getNameInfo(m.getNameInfo(), acceptLanguage).getShortName();
            this.subjectType = SubjectTypeEnum.DEPARTMENT;
        }
    }
}
